define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'fangyuan/index',
                    add_url: 'fangyuan/add',
                    edit_url: 'fangyuan/edit',
                    del_url: 'fangyuan/del',
                    multi_url: 'fangyuan/multi',
                    table: 'fangyuan',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title')},
                        {field: 'state_text', title: __('State'), operate:false},
                        {field: 'address', title: __('Address')},
                        {field: 'fangdong', title: __('Fangdong')},
                        {field: 'fd_tel', title: __('Fd_tel')},
                        {field: 'fd_idcardimage', title: __('Fd_idcardimage'), formatter: Table.api.formatter.image},
                        {field: 'fd_idcard', title: __('Fd_idcard')},
                        {field: 'zl_rent', title: __('Zl_rent')},
                        {field: 'zl_type_text', title: __('Zl_type'), operate:false},
                        {field: 'zl_starttime', title: __('Zl_starttime'), formatter: Table.api.formatter.datetime},
                        {field: 'zl_endtime', title: __('Zl_endtime'), formatter: Table.api.formatter.datetime},
                        {field: 'rentid', title: __('Rentid')},
                        {field: 'rent.user', title: __('Rent.user')},
                        {field: 'income', title: __('Income')},
                        {field: 'expenditure', title: __('Expenditure')},
                        {field: 'operate', title: __('Operate'),buttons: [
                                {name: 'rentindex', text: '租户', title: '租户', icon: 'fa fa-list', classname: 'btn btn-xs btn-primary btn-dialog', url: 'rent/index'},
                                {name: 'caiwu', text: '财务明细', title: '财务明细', icon: 'fa fa-flash', classname: 'btn btn-xs btn-success btn-dialog', url: 'Caiwu/index'},
                                {name: 'touzirenindex', text: '投资人', title: '投资人', icon: 'fa fa-flash', classname: 'btn btn-xs btn-info btn-dialog', url: 'touziren/index'}
                            ],  table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});